package com.fare.taluo.util;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.fare.taluo.vo.fetl.FreightMonitorChartVO;
import com.fare.taluo.vo.fetl.FreightMonitorVO;

public class XmlUtil {
	private static String lowestPrice = null;
	private static String hightestPrice=null;
	private static String seatKilometer = null;
	private static String passengerLoad = null;
	private static String flighNos = null;
	private static String flighLeg = null;
	private static String grabSeq = null;
	private static String daySeq = null;
	private static String times = null;
	private static String totalCabins = null;
	private static String addCabins = null;
	private static String delCabins = null;
	private static String grabCompany=null;
	
	static{
		Locale locale =  ServletActionContext.getContext().getLocale();
		lowestPrice  = I18nUtil.getProperties(locale).get("xmlutil.lowestPrice");
		hightestPrice  = I18nUtil.getProperties(locale).get("xmlutil.hightestPrice");
		seatKilometer = I18nUtil.getProperties(locale).get("xmlutil.seatKilometer");
		passengerLoad = I18nUtil.getProperties(locale).get("xmlutil.passengerLoad");
		flighNos=I18nUtil.getProperties(locale).get("xmlutil.flighNo");
		flighLeg=I18nUtil.getProperties(locale).get("xmlutil.flighLeg");
		grabSeq=I18nUtil.getProperties(locale).get("xmlutil.grabSeq");
		daySeq=I18nUtil.getProperties(locale).get("xmlutil.daySeq");
		times=I18nUtil.getProperties(locale).get("xmlutil.times");
		totalCabins=I18nUtil.getProperties(locale).get("xmlutil.totalCabins");
		addCabins=I18nUtil.getProperties(locale).get("xmlutil.addCabins");
		delCabins=I18nUtil.getProperties(locale).get("xmlutil.delCabins");
		grabCompany=I18nUtil.getProperties(locale).get("xmlutil.grabCompany");
		
	}
	
	public static void changeLocale(Locale locale){
		lowestPrice  = I18nUtil.getProperties(locale).get("xmlutil.lowestPrice");
		hightestPrice  = I18nUtil.getProperties(locale).get("xmlutil.hightestPrice");
		seatKilometer = I18nUtil.getProperties(locale).get("xmlutil.seatKilometer");
		passengerLoad = I18nUtil.getProperties(locale).get("xmlutil.passengerLoad");
		flighNos=I18nUtil.getProperties(locale).get("xmlutil.flighNo");
		flighLeg=I18nUtil.getProperties(locale).get("xmlutil.flighLeg");
		grabSeq=I18nUtil.getProperties(locale).get("xmlutil.grabSeq");
		daySeq=I18nUtil.getProperties(locale).get("xmlutil.daySeq");
		times=I18nUtil.getProperties(locale).get("xmlutil.times");
		totalCabins=I18nUtil.getProperties(locale).get("xmlutil.totalCabins");
		addCabins=I18nUtil.getProperties(locale).get("xmlutil.addCabins");
		delCabins=I18nUtil.getProperties(locale).get("xmlutil.delCabins");
		grabCompany=I18nUtil.getProperties(locale).get("xmlutil.grabCompany");
	}
	public static String getXMLmonitor(String tableName,
			List<String> flightNoNum, List<String> numbersCount,
			List<Map<String, String>> data) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  palette='2' useRoundEdges='0' caption='"
				+ tableName
				+ "' shownames='1' showvalues='1' showSum='0' decimals='0' useRoundEdges='1' baseFont='Arial' baseFontSize='12' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		for (String s : numbersCount) {
			XML += "<category label='" + s + "'/>";
		}
		XML += "</categories>";
		int i = 0;
		Map<String, List<String>> flino = new HashMap<String, List<String>>();// 为KEY的舱位数

		for (Map<String, String> fli : data) {
			for (String fliKey : fli.keySet()) {
				if (flino.get(fliKey) == null) {
					// flino.get(fliKey).clear();
					flino.put(fliKey, new ArrayList<String>());
				}
				String ss = fliKey;
				// String ss=data.get(fli).get(fliKey);
				// System.out.println("data.get(fli).get(fliKey):"+ss);
				String st = fli.get(fliKey);
				// System.out.println("flino.get(fliKey):"+st);
				flino.get(fliKey).add(st);
				// flino.get(fliKey).add(data.get(fli).get(fliKey));
			}
		}
		// Map<String, Integer> m = entry.getValue();

		if (flightNoNum.size() != 0) {
			for (String flighLines : flightNoNum) {
				String color = "#CE428";
				i++;
				if (i == 1) {
					color = "4A6FB1";
				} else if (i == 1) {
					color = "A4483D";
				} else if (i == 2) {
					color = "8DA71E";
				} else if (i == 3) {
					color = "FF00FF";
				} else if (i == 4) {
					color = "00FF00";
				} else if (i == 5) {
					color = "3399CC";
				} else if (i == 6) {
					color = "9900FF";
				} else if (i == 7) {
					color = "CC3333";
				} else if (i == 8) {
					color = "3399CC";
				} else if (i == 9) {
					color = "3399CC";
				}
				XML += "<dataset seriesName='" + flighLines
						+ "' anchorRadius='5' color='" + color + "' >";
				/*
				 * 舱位数
				 */
				if (flino.get(flighLines) != null) {
					for (String numVlues : flino.get(flighLines)) {

						XML += "<set value='" + numVlues + "' />";
					}
				} else {
					// for(int n=0;n<numbersCount.size();n++){
					 XML += "<set />";
					// }
				}
				XML += "</dataset>";
			}
		}
		/*
		 * XML +=
		 * "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
		 * "	<set value='500'/>"+ "<set value='700'/>"+ "<set value='900'/>"+
		 * "<set value='1100'/>"+ "<set value='1300'/>"+ "</lineset>"+
		 * "</chart>";
		 */
		XML += "</chart>";

		return XML;
	}

	private static Map<String, List<FreightMonitorVO>> convertMapsData(
			List<FreightMonitorChartVO> chartVOs) {
		Map<String, List<FreightMonitorVO>> xmlDatas = new HashMap<String, List<FreightMonitorVO>>();
		// 4、转成航班号对应list, 航班下的某一天数据可能为空
		for (FreightMonitorChartVO vo : chartVOs) {
			for (FreightMonitorVO dateVo : vo.getMonitorVOs()) {
				if (xmlDatas.get(dateVo.getFlightNo()) == null) {
					xmlDatas.put(dateVo.getFlightNo(),
							new ArrayList<FreightMonitorVO>());
				}
				xmlDatas.get(dateVo.getFlightNo()).add(dateVo);
			}
		}
		return xmlDatas;
	}

	public static Map<Integer, String> staticChartColors = new HashMap<Integer, String>();
	static {
		staticChartColors.put(0, "4A6FB1");
		staticChartColors.put(1, "A4483D");
		staticChartColors.put(2, "8DA71E");
		staticChartColors.put(3, "FF00FF");
		staticChartColors.put(4, "00FF00");
		staticChartColors.put(5, "3399CC");
		staticChartColors.put(6, "9900FF");
		staticChartColors.put(7, "CC3333");
	}

	public static String getCabinXMLmonitor(String tableName,
			List<String> flightNos, List<FreightMonitorChartVO> chartVOs) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  palette='2' useRoundEdges='0' caption='"
				+ tableName
				+ "' shownames='1' showvalues='1' showSum='0'  useRoundEdges='1' baseFont='Arial' baseFontSize='12' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		if(chartVOs != null && chartVOs.size() >0){
			for (FreightMonitorChartVO vo : chartVOs) {
				XML += "<category label='" + vo.getGrabNumXDesc() + "'/>";
				}
			}else{
					XML += "<category label=''/>";
					}
		XML += "</categories>";
		int i = 0;
		Map<String, List<FreightMonitorVO>> xmlDatas = convertMapsData(chartVOs);

		if (flightNos.size() != 0) {
			for (String flightNo : flightNos) {
			//	System.out.println("flinthNo"+flightNo);
				XML += "<dataset seriesName='" + flightNo
						+ "' anchorRadius='5' color='"
						+ staticChartColors.get(i++) + "' >";
				if(xmlDatas.get(flightNo) != null){
					for (FreightMonitorVO vo : xmlDatas.get(flightNo)) {
						XML += "<set value='" + (vo.getCabinNum()>0 ? vo.getCabinNum() : "")  + "' toolText='"+flighNos+flightNo+"{br} "+flighLeg+vo.getFromCityName()+"("+vo.getFromCity()+")—"+vo.getToCityName()+"("+vo.getToCity()+"){br} "+grabCompany+vo.getGrabChannel()+"{br} "+
								grabSeq+vo.getGrabDate().toString().substring(8,10)+daySeq+vo.getGrabNum()+times+"{br} " +
								totalCabins+vo.getCabinNum()+"{br} "+addCabins+vo.getCabinNumForAdd()+" {br} "+delCabins+vo.getCabinNumForDel()+" ' />";
					}
				}
				
				//grabDate.substring(8) + "日第" + this.grabNum + "次";
				else{
					XML += "<set />";
				}
				XML += "</dataset>";
			}
		}
		XML += "</chart>";

		return XML;
	}

	// 运价监控所用的XML 参数分别为：表名,航班号，舱位
	public static String getLowerXMLmonitor(String tableName,
			List<String> flightNos, List<FreightMonitorChartVO> chartVOs, int minPrice) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  caption='"
				+ tableName
				+ "' shownames='1'  yAxisMinValue='"
				+ minPrice
				+ "' showvalues='0' showSum='0'  useRoundEdges='1' baseFont='Arial' baseFontSize='12' NUMBERPREFIX='￥' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		if(chartVOs.size()>0 && chartVOs != null){
			for (FreightMonitorChartVO vo : chartVOs) {
				XML += "<category label='" + vo.getGrabNumXDesc() + "'/>";
			}
		}else{
			XML += "<category label=''/>";
		}
		XML += "</categories>";
		int i = 0;
		Map<String, List<FreightMonitorVO>> xmlDatas = convertMapsData(chartVOs);

		if (flightNos.size() != 0) {
			for (String flightNo : flightNos) {
				XML += "<dataset seriesName='" + flightNo
						+ "' anchorRadius='5' color='"
						+ staticChartColors.get(i++) + "' >";
				if(xmlDatas.get(flightNo) != null){
					for (FreightMonitorVO vo : xmlDatas.get(flightNo)) {
						XML += "<set value='"
								+ (vo.getLowerPrice() > 0 ? vo.getIntLowerPrice()
										: "") + "'   toolText='"+flighNos+flightNo+"{br} "+flighLeg+vo.getFromCityName()+"("+vo.getFromCity()+")—"+vo.getToCityName()+"("+vo.getToCity()+"){br} "+grabCompany+vo.getGrabChannel()+"{br} "+grabSeq+vo.getGrabDate().toString().substring(8,10)+daySeq+vo.getGrabNum()+times+"{br} "+lowestPrice+"￥"+vo.getIntLowerPrice()+"'/>";
					}
				}else{
					XML += "<set />";
				}
				XML += "</dataset>";
			}
		}
		XML += "</chart>";

		return XML;
	}

	public static String getHighXMLmonitor(String tableName,
			List<String> flightNos, List<FreightMonitorChartVO> chartVOs, int maxPrice) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  caption='"
				+ tableName
				+ "' shownames='1'  yAxisMinValue='"
				+ maxPrice
				+ "' showvalues='0' showSum='0' useRoundEdges='1' baseFont='Arial' baseFontSize='12' NUMBERPREFIX='￥' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		if(chartVOs.size()>0 && chartVOs !=null){
			for (FreightMonitorChartVO vo : chartVOs) {
				XML += "<category label='" + vo.getGrabNumXDesc() + "'/>";
			}
		}else{
			XML += "<category label=''/>";
		}
		XML += "</categories>";
		int i = 0;
		Map<String, List<FreightMonitorVO>> xmlDatas = convertMapsData(chartVOs);

		if (flightNos.size() != 0) {
			for (String flightNo : flightNos) {
				XML += "<dataset seriesName='" + flightNo
						+ "' anchorRadius='5' color='"
						+ staticChartColors.get(i++) + "' >";
				if(xmlDatas.get(flightNo) != null){
					for (FreightMonitorVO vo : xmlDatas.get(flightNo)) {
						XML += "<set value='"
								+ (vo.getHigherPrice() > 0 ? vo.getIntHigherPrice()
										: "") + "'toolText='"+flighNos+flightNo+"{br} "+flighLeg+vo.getFromCityName()+"("+vo.getFromCity()+")—"+vo.getToCityName()+"("+vo.getToCity()+"){br} "+grabCompany+vo.getGrabChannel()+"{br} "+grabSeq+vo.getGrabDate().toString().substring(8,10)+daySeq+vo.getGrabNum()+times+"{br} "+hightestPrice+"￥"+vo.getIntHigherPrice()+" '/>";
					}
				}else{
					XML += "<set />";
				}
				XML += "</dataset>";
			}
		}
		XML += "</chart>";

		return XML;
	}

	// 运价监控所用的XML 参数分别为：表名,航班号，舱位
	public static String getXMLmonitor2(String tableName,
			List<String> flightNoNum, List<String> numbersCount,
			List<Map<String, String>> data, int minPrice) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  palette='2'  caption='"
				+ tableName
				+ "' shownames='1'  yAxisMinValue='"
				+ minPrice
				+ "' showvalues='1' showSum='0'  useRoundEdges='1' baseFont='Arial' baseFontSize='12' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		for (String s : numbersCount) {
			XML += "<category label='" + s + "'/>";
		}
		XML += "</categories>";
		int i = 0;
		Map<String, List<String>> flino = new HashMap<String, List<String>>();// 为KEY的舱位数

		for (Map<String, String> fli : data) {
			for (String fliKey : fli.keySet()) {
				if (flino.get(fliKey) == null) {
					// flino.get(fliKey).clear();
					flino.put(fliKey, new ArrayList<String>());
				}
				String ss = fliKey;
				// String ss=data.get(fli).get(fliKey);
				// System.out.println("data.get(fli).get(fliKey):"+ss);
				String st = fli.get(fliKey);
				// System.out.println("flino.get(fliKey):"+st);
				flino.get(fliKey).add(st);
				// flino.get(fliKey).add(data.get(fli).get(fliKey));
			}
		}
		// Map<String, Integer> m = entry.getValue();

		if (flightNoNum.size() != 0) {
			for (String flighLines : flightNoNum) {
				String color = "#CE428";
				i++;
				if (i == 1) {
					color = "4A6FB1";
				} else if (i == 1) {
					color = "A4483D";
				} else if (i == 2) {
					color = "8DA71E";
				} else if (i == 3) {
					color = "FF00FF";
				} else if (i == 4) {
					color = "00FF00";
				} else if (i == 5) {
					color = "3399CC";
				} else if (i == 6) {
					color = "9900FF";
				} else if (i == 7) {
					color = "CC3333";
				} else if (i == 8) {
					color = "3399CC";
				} else if (i == 9) {
					color = "3399CC";
				}
				XML += "<dataset seriesName='" + flighLines
						+ "' anchorRadius='5' color='" + color + "' >";
				/*
				 * 舱位数
				 */
				if (flino.get(flighLines) != null) {
					for (String numVlues : flino.get(flighLines)) {
						XML += "<set value='" + numVlues + "' />";
					}
				} else {
					// for(int n=0;n<numbersCount.size();n++){
					XML += "<set  />";
					// }
				}
				XML += "</dataset>";
			}
		}
		/*
		 * XML +=
		 * "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
		 * "	<set value='500'/>"+ "<set value='700'/>"+ "<set value='900'/>"+
		 * "<set value='1100'/>"+ "<set value='1300'/>"+ "</lineset>"+
		 * "</chart>";
		 */
		XML += "</chart>";

		return XML;
	}

	// 运价监控所用的XML 参数分别为：表名,航班号，舱位
	public static String getXMLmonitor3(String tableName,
			List<String> flightNoNum, List<String> numbersCount,
			List<Map<String, String>> data, int minPrice) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  palette='2'  caption='"
				+ tableName
				+ "' shownames='1' showvalues='1'  yAxisMinValue='"
				+ minPrice
				+ "' showSum='0' decimals='0' useRoundEdges='1' baseFont='Arial' baseFontSize='' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		for (String s : numbersCount) {
			XML += "<category label='" + s + "'/>";
		}
		XML += "</categories>";
		int i = 0;
		Map<String, List<String>> flino = new HashMap<String, List<String>>();// 为KEY的舱位数

		for (Map<String, String> fli : data) {
			for (String fliKey : fli.keySet()) {
				if (flino.get(fliKey) == null) {
					// flino.get(fliKey).clear();
					flino.put(fliKey, new ArrayList<String>());
				}
				String ss = fliKey;
				// String ss=data.get(fli).get(fliKey);
				// System.out.println("data.get(fli).get(fliKey):"+ss);
				String st = fli.get(fliKey);
				// System.out.println("flino.get(fliKey):"+st);
				flino.get(fliKey).add(st);
				// flino.get(fliKey).add(data.get(fli).get(fliKey));
			}
		}
		// Map<String, Integer> m = entry.getValue();

		if (flightNoNum.size() != 0) {
			for (String flighLines : flightNoNum) {
				String color = "#CE428";
				i++;
				if (i == 1) {
					color = "4A6FB1";
				} else if (i == 1) {
					color = "A4483D";
				} else if (i == 2) {
					color = "8DA71E";
				} else if (i == 3) {
					color = "FF00FF";
				} else if (i == 4) {
					color = "00FF00";
				} else if (i == 5) {
					color = "3399CC";
				} else if (i == 6) {
					color = "9900FF";
				} else if (i == 7) {
					color = "CC3333";
				} else if (i == 8) {
					color = "3399CC";
				} else if (i == 9) {
					color = "3399CC";
				}
				XML += "<dataset seriesName='" + flighLines
						+ "' anchorRadius='5' color='" + color + "' >";
				/*
				 * 舱位数
				 */
				if (flino.get(flighLines) != null) {
					for (String numVlues : flino.get(flighLines)) {

						XML += "<set value='" + numVlues + "' />";
					}
				} else {
					// for(int n=0;n<numbersCount.size();n++){
					 XML += "<set  />";
					// }
				}
				XML += "</dataset>";
			}
		}
		/*
		 * XML +=
		 * "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
		 * "	<set value='500'/>"+ "<set value='700'/>"+ "<set value='900'/>"+
		 * "<set value='1100'/>"+ "<set value='1300'/>"+ "</lineset>"+
		 * "</chart>";
		 */
		XML += "</chart>";

		return XML;
	}

	// 运价监控所用的XML 参数分别为：表名,航班号，舱位
	public static String getXMLmonitorH(String tableName,
			List<String> flightNoNum, List<String> numbersCount,
			List<Map<String, String>> data) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  palette='2'  caption='"
				+ tableName
				+ "' shownames='1' showvalues='0' showSum='0' decimals='0' useRoundEdges='1' baseFont='Arial' baseFontSize='12' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		for (String s : numbersCount) {
			XML += "<category label='" + s + "'/>";
		}
		XML += "</categories>";
		int i = 0;
		Map<String, List<String>> flino = new HashMap<String, List<String>>();// 为KEY的舱位数

		for (Map<String, String> fli : data) {
			for (String fliKey : fli.keySet()) {
				if (flino.get(fliKey) == null) {
					// flino.get(fliKey).clear();
					flino.put(fliKey, new ArrayList<String>());
				}
				String ss = fliKey;
				// String ss=data.get(fli).get(fliKey);
				// System.out.println("data.get(fli).get(fliKey):"+ss);
				String st = fli.get(fliKey);
				// System.out.println("flino.get(fliKey):"+st);
				flino.get(fliKey).add(st);
				// flino.get(fliKey).add(data.get(fli).get(fliKey));
			}
		}
		// Map<String, Integer> m = entry.getValue();

		if (flightNoNum.size() != 0) {
			for (String flighLines : flightNoNum) {
				String color = "#CE428";
				i++;
				if (i == 1) {
					color = "4A6FB1";
				} else if (i == 1) {
					color = "A4483D";
				} else if (i == 2) {
					color = "8DA71E";
				} else if (i == 3) {
					color = "FF00FF";
				} else if (i == 4) {
					color = "00FF00";
				} else if (i == 5) {
					color = "3399CC";
				} else if (i == 6) {
					color = "9900FF";
				} else if (i == 7) {
					color = "CC3333";
				} else if (i == 8) {
					color = "3399CC";
				} else if (i == 9) {
					color = "3399CC";
				}
				XML += "<dataset seriesName='" + flighLines
						+ "' anchorRadius='5' color='" + color + "' >";
				/*
				 * 舱位数
				 */
				for (String numVlues : flino.get(flighLines)) {
					XML += "<set value='" + numVlues
							+ "' link='JavaScript:alert(" + flighLines
							+ ");'/>";
				}
				XML += "</dataset>";
			}
		}
		/*
		 * XML +=
		 * "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
		 * "	<set value='500'/>"+ "<set value='700'/>"+ "<set value='900'/>"+
		 * "<set value='1100'/>"+ "<set value='1300'/>"+ "</lineset>"+
		 * "</chart>";
		 */
		XML += "</chart>";

		return XML;
	}

	// 运价监控所用的XML 参数分别为：表名,航班号，舱位
	public static String getXMLmonitorD(String tableName,
			List<String> flightNoNum, List<String> numbersCount,
			List<Map<String, String>> data) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart  palette='2'  caption='"
				+ tableName
				+ "' shownames='1' showvalues='0' showSum='0' decimals='0' useRoundEdges='1' baseFont='Arial' baseFontSize='12' rotateYAxisName='0' labelDisplay='Rotate' slantLabels='1'><categories>";
		for (String s : numbersCount) {
			XML += "<category label='" + s + "'/>";
		}
		XML += "</categories>";
		int i = 0;
		Map<String, List<String>> flino = new HashMap<String, List<String>>();// 为KEY的舱位数

		for (Map<String, String> fli : data) {
			for (String fliKey : fli.keySet()) {
				if (flino.get(fliKey) == null) {
					// flino.get(fliKey).clear();
					flino.put(fliKey, new ArrayList<String>());
				}
				String ss = fliKey;
				// String ss=data.get(fli).get(fliKey);
				// System.out.println("data.get(fli).get(fliKey):"+ss);
				String st = fli.get(fliKey);
				// System.out.println("flino.get(fliKey):"+st);
				flino.get(fliKey).add(st);
				// flino.get(fliKey).add(data.get(fli).get(fliKey));
			}
		}
		// Map<String, Integer> m = entry.getValue();

		if (flightNoNum.size() != 0) {
			for (String flighLines : flightNoNum) {
				String color = "#CE428";
				i++;
				if (i == 1) {
					color = "4A6FB1";
				} else if (i == 1) {
					color = "A4483D";
				} else if (i == 2) {
					color = "8DA71E";
				} else if (i == 3) {
					color = "FF00FF";
				} else if (i == 4) {
					color = "00FF00";
				} else if (i == 5) {
					color = "3399CC";
				} else if (i == 6) {
					color = "9900FF";
				} else if (i == 7) {
					color = "CC3333";
				} else if (i == 8) {
					color = "3399CC";
				} else if (i == 9) {
					color = "3399CC";
				}
				XML += "<dataset seriesName='" + flighLines
						+ "' anchorRadius='5' color='" + color + "' >";
				/*
				 * 舱位数
				 */
				for (String numVlues : flino.get(flighLines)) {
					XML += "<set value='" + numVlues + "' />";
				}
				XML += "</dataset>";
			}
		}
		/*
		 * XML +=
		 * "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
		 * "	<set value='500'/>"+ "<set value='700'/>"+ "<set value='900'/>"+
		 * "<set value='1100'/>"+ "<set value='1300'/>"+ "</lineset>"+
		 * "</chart>";
		 */
		XML += "</chart>";

		return XML;
	}

	public static String getXML(Map<String, List<String>> airPrice,
			List<String> dates, String tableName) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart caption='"
				+ tableName
				+ "' subCaption='For the year 2012' numberPrefix='￥' "
				+ "sformatNumberScale='10' sNumberPrefix='￥' syncAxisLimits='1' rotateValues='0' showSum='0' "
				+ "yAxisValuesPadding='15' chartRightMargin='25' palette='3'><categories>";
		for (String s : dates) {
			XML += "<category label='" + s.substring(5) + "'/>";
		}

		XML += "</categories>";
		int i = 0;
		if (airPrice != null) {
			for (String key : airPrice.keySet()) {
				String color = "#CE428";
				i++;
				if (i == 1) {
					color = "3300CC";
				} else if (i == 1) {
					color = "FF6633";
				} else if (i == 2) {
					color = "FF0000";
				} else if (i == 3) {
					color = "FF00FF";
				} else if (i == 4) {
					color = "00FF00";
				} else if (i == 5) {
					color = "3399CC";
				} else if (i == 6) {
					color = "9900FF";
				} else if (i == 7) {
					color = "CC3333";
				} else if (i == 8) {
					color = "3399CC";
				} else if (i == 9) {
					color = "3399CC";
				}
				XML += "<dataset seriesName='" + key
						+ "' anchorRadius='5' color='" + color + "'>";
				for (String price : airPrice.get(key)) {
					XML += "<set value='" + price + "'/>";
				}
				XML += "</dataset>";
			}
		}
		XML += "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"
				+ "	<set value='500'/>"
				+ "<set value='700'/>"
				+ "<set value='900'/>"
				+ "<set value='1100'/>"
				+ "<set value='1300'/>" + "</lineset>" + "</chart>";
		return XML;
	}

	public static String getXML(Map<String, Map<String, String>> airPrice,
			List<String> dates, List<String> airCompanies, String tableName) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart caption='"
				+ tableName
				+ "' subCaption='For the year 2012' numberPrefix='￥' "
				+ "sformatNumberScale='10' sNumberPrefix='￥' syncAxisLimits='1' rotateValues='1' showSum='0'><categories>";
		for (String s : dates) {
			XML += "<category label='" + s.substring(5) + "'/>";
		}
		XML += "</categories>";
		Map<String, List<String>> priceOfAirCompany = new HashMap<String, List<String>>();// 航空公司为key的价格列表(对应日期)
		for (String date : dates) {// 重新组织数据结构
			for (String priceKey : airPrice.get(date).keySet()) {
				if (priceOfAirCompany.get(priceKey) == null) {
					priceOfAirCompany.put(priceKey, new ArrayList<String>());// 新增未添加的航空公司
				}
				priceOfAirCompany.get(priceKey).add(
						airPrice.get(date).get(priceKey));
			}
		}
		for (String companyName : airCompanies) {
			XML += "<dataset seriesName='" + companyName
					+ "' anchorRadius='5'>";
			for (String price : priceOfAirCompany.get(companyName)) {
				XML += "<set value='" + price + "'/>";
			}
			XML += "</dataset>";
		}
		XML += "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"
				+ "	<set value='500'/>"
				+ "<set value='700'/>"
				+ "<set value='900'/>"
				+ "<set value='1100'/>"
				+ "<set value='1300'/>" + "</lineset>" + "</chart>";
		return XML;
	}

	// 参数 航班号，运价，运价类型
	public static String getXML(List<String> listhx,
			Map<String, List<Integer>> maplist,
			Map<String, List<Integer>> maplist2) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart palette='2' showLabels='1' showvalues='1' decimals='2' numberPrefix='￥' animation='1' labelDisplay='STAGGER' staggerLines='5' bgSWFAlpha='50' canvasBgColor='FFFFFF' canvasBorderThickness='1'><categories>";
		for (String hx : listhx) {
			XML += "<category label='" + hx + "' value='" + hx + "'/>";
		}
		XML += "</categories>";
		for (String ls : maplist.keySet()) {
			XML += "<dataset seriesName='" + ls
					+ "' showValues='1' color='8DA71E'>";
			for (Integer lp : maplist.get(ls)) {
				XML += "<set color='8DA71E' value='" + lp + "'/>";
			}
		}
		XML += "</dataset>";
		for (String ls : maplist2.keySet()) {
			XML += "<dataset seriesName='" + ls
					+ "' showValues='1' color='4A6FB1'>";
			for (Integer lp : maplist2.get(ls)) {
				XML += "<set color='4A6FB1' value='" + lp + "'/>";
			}
		}
		XML += "</dataset>";
		XML += "</chart>";
		/*
		 * XML +=
		 * "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"+
		 * "	<set value='500'/>"+ "<set value='700'/>"+ "<set value='900'/>"+
		 * "<set value='1100'/>"+ "<set value='1300'/>"+ "</lineset>"+
		 * "</chart>";
		 */
		return XML;
	}

	// 用于首页趋势图报表显示
	public static String getXML2(Map<String, List<String>> airPrice,
			List<String> dates, String tableName) {
		String XML = "<?xml version='1.0'?>"
				+ "<chart caption='"
				+ tableName
				+ "'  numberPrefix='￥' "
				+ "sformatNumberScale='10' sNumberPrefix='￥' syncAxisLimits='1' rotateValues='0' showSum='0' "
				+ "yAxisValuesPadding='15' chartRightMargin='25' palette='3' labelDisplay='ROTATE' slantLabels='0' ><categories>";
		// categories子集category个数与dataset子集set个数要一致
		for (String s : dates) {
			XML += "<category label='" + s.substring(5) + "'/>";
		}

		XML += "</categories>";
		int i = 0;
		if (airPrice != null) {
			for (String key : airPrice.keySet()) {
				String color = "#CE428";
				i++;
				if (i == 1) {
					color = "3300CC";
				} else if (i == 1) {
					color = "FF6633";
				} else if (i == 2) {
					color = "FF0000";
				} else if (i == 3) {
					color = "FF00FF";
				} else if (i == 4) {
					color = "00FF00";
				} else if (i == 5) {
					color = "3399CC";
				} else if (i == 6) {
					color = "9900FF";
				} else if (i == 7) {
					color = "CC3333";
				} else if (i == 8) {
					color = "3399CC";
				} else if (i == 9) {
					color = "3399CC";
				}
				XML += "<dataset seriesName='" + key
						+ "' anchorRadius='5' color='" + color + "'>";
				for (String price : airPrice.get(key)) {
					XML += "<set value='" + price + "'/>";
				}
				XML += "</dataset>";
			}
		}
		XML += "<lineset seriesName='Target Profitability' valuePosition='BELOW'>"
				+ "	<set value='500'/>"
				+ "<set value='700'/>"
				+ "<set value='900'/>"
				+ "<set value='1100'/>"
				+ "<set value='1300'/>" + "</lineset>" + "</chart>";
		return XML;
	}

	// 用于首页柱状图报表显示
	public static String getXML3(HashMap<String, List<String>> map) {
		String XML = "<chart  showValues='0' numberPrefix='￥' sNumberSuffix='' decimals='3' setAdaptiveYMin='1' setAdaptiveSYMin='1' lineThickness='5' showBorder='0' bgColor='FFFFFF' canvasBgColor='FFFFFF' showBorder='0' labelDisplay='ROTATE'>";
		// categories子集category个数与dataset子集set个数要一致
		XML += "<categories>";
		DecimalFormat decfmt = new DecimalFormat("##0.000");
		for (String str : map.keySet()) {
			XML += " <category label='" + str + "' />";
		}
		XML += "</categories>";
		XML += "<dataset seriesName='"+lowestPrice+"' parentYAxis='P'  color='4A6FB1' showValues='1'>";
		for (String str : map.keySet()) {
			XML += " <set value='" + map.get(str).get(0) + "' toolText='"
					+ map.get(str).get(1) + "'/>";
		}
		XML += "</dataset>";
		XML += "<dataset seriesName='"+seatKilometer+"' renderAs='Column'  parentYAxis='S' color='A4493F' showValues='1'>";
		for (String str : map.keySet()) {
			if (map.get(str).size() > 2) {
				String s = map.get(str).get(3);
				if (StringUtils.isEmpty(s)) {
					XML += " <set value='' />";
				} else {
					XML += " <set value='"
							+ decfmt.format(Float.parseFloat(s) / 1000)
							+ "' />";
				}
			}
		}
		XML += "</dataset>";

		XML += "<dataset seriesName='"+passengerLoad+"'  parentYAxis='S' color='8DA71E' renderAs='Column' showValues='1'>";
		for (String str : map.keySet()) {
			if (map.get(str).size() > 3) {
				String s2 = map.get(str).get(3);
				if (StringUtils.isEmpty(s2)) {
					XML += " <set value='' />";
				} else {
					XML += " <set value='"
							+ decfmt.format(Float.parseFloat(s2) / 100)
							+ "' />";

				}
			}
		}
		XML += "</dataset>";
		// XML +=
		// "<dataset seriesName=''  parentYAxis='' color='' showValues='1'>";//抓取时间
		// for(String str:map.keySet()){
		// if(map.get(str).size()>3){
		// XML += " <set value='"+map.get(str).get(3)+"' />";
		// }
		// }
		// XML += "</dataset>";
		XML += "</chart>";
		return XML;
	}

}
